#!-*- encoding:utf8 -*-
from django.db import models
from django.contrib.auth.models import User
from newosmp.define import *

# Create your models here.
class HostModel(models.Model):
    name = models.CharField(max_length=50)  #机器型号
    cpu = models.CharField(max_length=50)     #CPU描述
    mem = models.CharField(max_length=50)     #内存描述
    disk = models.CharField(max_length=50)    #磁盘描述
    network = models.CharField(max_length=50) #网络描述
    other = models.CharField(max_length=50, blank=True)
    
    def __unicode__(self):
        return "%s" % (self.name)

    def __str__(self):
        return "%s" % (self.name)


class Product(models.Model):
    name = models.CharField(max_length=20)
    #pm = models.ForeignKey(User, blank=True)
    #rd = models.ForeignKey(User, blank=True)
    op = models.ForeignKey(User, blank=True)
    has_host = models.CharField(max_length=1, choices= CH_TRUE_FALSE)
    ppid = models.IntegerField()    #子

    def __unicode__(self):
        return u"%s" % self.name

    def __str__(self):
        return "%s" % self.name


class IDC(models.Model):
    name = models.CharField(max_length=20)
    num = models.IntegerField(default=0)

    def __unicode__(self):
        return "%s" % self.name

    def __str__(self):
        return "%s" % self.name


class Host(models.Model):
    ip = models.IPAddressField(unique=True)
    idc = models.ForeignKey(IDC)
    name = models.CharField(max_length=50)
    setup_time = models.DateField()      #上架时间
    mid = models.ForeignKey(HostModel)
    pid = models.ForeignKey(Product)
    status = models.CharField(max_length=1, choices= CH_TRUE_FALSE)
    r_cpu_core = models.FloatField(blank=True)
    r_cpu_usage = models.FloatField(blank=True)
    r_cpu_model = models.CharField(max_length=50, blank = True)
    r_mem_usage = models.FloatField(blank=True)
    r_mem_total = models.FloatField(blank=True)
    r_load = models.FloatField(blank=True)
    r_disk = models.FloatField(blank=True)
    r_disk_total = models.FloatField(blank=True)
    r_network = models.FloatField(blank=True)
    r_uptime = models.DateTimeField(blank=True)
    r_os =  models.CharField(max_length=50, blank = True)
    timestamp = models.DateTimeField(auto_now_add=True)


    def __unicode__(self):
        return "%s [%s]" % (self.name, self.ip)

    def __str__(self):
        return "%s [%s]" % (self.name, self.ip)



